package com.itheima.listener;

import java.util.Map;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import com.alibaba.fastjson.JSON;
import com.itheima.config.ActiveMqBean;
import com.itheima.utils.AliSendUtils;

@Component
public class ActiveListener {

    /**
     * 监听短信验证码 队列
     */
    @JmsListener(destination = ActiveMqBean.MyQueue)
    public void readMsg(String msg){ // 必须是json字符串接受
        Map<String, String> map = JSON.parseObject(msg, Map.class);
        if(!ObjectUtils.isEmpty(map)){
            // 取出map中的验证码和用户号码
            String phone = map.get("phone");
            String sysCode = map.get("sysCode");
            // 调用阿里大于平台发送短信
            AliSendUtils.send(phone,sysCode);
        }
    }
}
